package com.asm.DBloader;

import java.util.ArrayList;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

public class ASM_UsersettingsDS {
	private SQLiteDatabase dB;
	private ASM_DB dbHelper;
	Context context;

	
	public ASM_UsersettingsDS (Context context)
	{
		this.context = context;
		dbHelper = new ASM_DB(context);
	}
	
	public void open() throws SQLException
	{
		dB = dbHelper.getWritableDatabase();
	}
	public int Create(ASM_Usersettings det) 
	{
		int count =0;
		if(dB == null)
		{
			open();
		}
		else if(!dB.isOpen())
		{
			open();
		}
		
		Cursor cursor = dB.rawQuery("select * from Usersettings ", null);
		
		if(cursor.getCount()>0)
			return -1;	
		
		ContentValues values = new ContentValues();
		values.put(ASM_DB.asmUSersettings_username, det.getAsmUSersettings_username());
		values.put(ASM_DB.asmUSersettings_asmprefix, det.getAsmUSersettings_asmprefix());
		values.put(ASM_DB.asmUSersettings_asmcode, det.getAsmUSersettings_asmcode());
		values.put(ASM_DB.asmUSersettings_serverdbname, det.getAsmUSersettings_serverdbname());
	
		count = (int) dB.insert(ASM_DB.ASM_USERSETTINGS, null, values);

		dB.close();
		return count;
		
	}
	
	public String getASMCode() 
	{
		if (dB == null) {
			open();
		} else if (!dB.isOpen()) {
			open();
		}
		
	
		String ASMCode = null;
		String selectQuery = "select asmcode from Usersettings";
		
		Cursor cursor = null;
		cursor = dB.rawQuery(selectQuery, null);
		
		while(cursor.moveToNext())
		{
		
			ASMCode = cursor.getString(0);
		
		}
		
		return ASMCode;
	}
}
